package com.captain.special.链表;

import com.captain.leetcode.链表.ListNode;

/**
 * Des:
 *
 * @author XL
 * @Date 2022/3/23 14:09
 */
public class 删除排序链表中的重复元素83 {

    public static void main(String[] args) {
        new 删除排序链表中的重复元素83().deleteDuplicates(ListNode.getInstance());
    }

    public ListNode deleteDuplicates(ListNode head) {
        if (head == null || head.next == null) return head;

        ListNode dummy = new ListNode(-1, head);
        while (head.next != null) {
            int val = head.val;
            int nextVal = head.next.val;
            if (val != nextVal) {
                head = head.next;
                continue;
            }
            //直接跳过
            ListNode next = head.next.next;
            //如果相等
            while (next != null && next.next != null) {
                int sNextVal = next.val;
                if (val == sNextVal) {
                    next = next.next;
                    continue;
                }
                break;
            }
            head.next = next;
        }
        return dummy.next;
    }
}
